﻿using GN.Pay.TradeChannel.DefaultImpl;
using GN.Pay.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.TradeChannel.YJPay.Request
{
    [Serializable]
    public class WebPayRequest : APayRequest
    {
        public override string service
        {
            get
            {
                return "fastPayTradeMergePay";
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="order"></param>
        /// <param name="config"></param>
        public WebPayRequest(IChannel channel,
           IOrderPayApply order,
           YJPayConfigure config)
        {
            this.orderNo = DateTime.Now.ToString("yyyyMMddHHmmssffffff");
            //this.orderNo = order.OrderNo;
            this.partnerId = config.ConfigureInfo.AccountId;
            this.version = "2.0";
            this.merchOrderNo = orderNo;
            this.tradeInfo = new List<tradeInfos> { new tradeInfos { currency = "CNY", goodsName = order.Subject, tradeAmount = order.OrderMoney, merchOrderNo = order.OrderNo, sellerUserId = config.ConfigureInfo.AccountId } }.ToJson(true);
            this.returnUrl = config.PayReturnUrl;
            this.notifyUrl = config.PayNotifyUrl;
            //  this.paymentType = "ONLINEBANK";
            //  this.userTerminalType = "PC";
            this.bankCode = "ABC";
            //this.personalCorporateType = "PERSONAL";
            //this.cardType = "DEBIT";
            context = order.ExtraParam;
        }  

        public string bankCode { get; set; }

        //  public string paymentType { get; set; }

        //  public string userTerminalType { get; set; }

        //public string personalCorporateType { get; set; }

        //public string cardType { get; set; }

        /// <summary>
        /// return 地址
        /// </summary>
        public string returnUrl { get; set; }

        /// <summary>
        /// 异步通知 地址
        /// </summary>
        public string notifyUrl { get; set; }

        /// <summary>
        /// 订单号 （16-40)请求流水号，商户的每次请求必须唯一。
        /// </summary>
        public string orderNo { get; set; }

        /// <summary>
        /// Api服务版本，与服务名称一起唯一标志一个服务   :1.0
        /// </summary>
        public string version { get; set; }

        /// <summary>
        /// 商户订单号和OrderNo一样
        /// </summary>
        public string merchOrderNo { get; set; }

        /// <summary>
        /// 公共上下文
        /// </summary>
        public string context { get; set; }

        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="config">配置</param>
        /// <returns></returns>
        public ITradePayApplyResult Build(ITradeChannel channel,
            YJPayConfigure config)
        {
            string urlParams = this.BuildSignUrlLinkParam(channel, config);
            return new TradePayApplyResult("", config.GatewayUrl, urlParams, TradePayApplyResultCallType.Web_Get);
        }
    }
}
